import java.util.Scanner;

public class demo06 {
    //滑行距离(dfs)
    public static int count=1;
    public static int max=0;
    public static int[] dx={0,1,0,-1};
    public static int[] dy={1,0,-1,0};
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int[][] arr=new int[n][m];
        int[][] num=new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j]=sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                count=1;
                num[i][j]=1;
                dfs(arr,num,i,j);
                num[i][j]=0;
            }
        }
        System.out.println(max);
    }
    public static void dfs(int[][] arr,int[][] num,int i,int j){
        for (int k = 0; k < 4; k++) {
            int i1=i+dx[k];
            int j1=j+dy[k];
            if(i1>=0&&i1<arr.length&&j1>=0&&j1<arr[i].length){
                if(arr[i1][j1]<arr[i][j]&&num[i1][j1]==0){
                    num[i1][j1]=1;
                    count++;
                    if(count>max){
                        max=count;
                    }
                    dfs(arr,num,i1,j1);
                    count--;
                    num[i1][j1]=0;
                }
            }
        }
    }
}
